﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmetic.DataEntity;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

namespace Cosmetic.Logic
{

    public class OrderManager : LogicBase
    {
        public void InsertOrder(Order anOrder)
        {
            m_CosmeticDC.Orders.InsertOnSubmit(anOrder);
            m_CosmeticDC.SubmitChanges();
        }
        public void DeleteOrder(Order anOrder)
        {
            foreach (var theOrderDetail in anOrder.OrderDetails)
            {
                DeleteOrderDetail(theOrderDetail);
            }
            m_CosmeticDC.Orders.DeleteOnSubmit(anOrder);
            m_CosmeticDC.SubmitChanges();
        }

        public Order GetOrderById(Guid? anOrderId)
        {
            return m_CosmeticDC.Orders.FirstOrDefault(theOrder => theOrder.OrderId == anOrderId);
        }

        public Order GetProductById(Guid aProductId)
        {
            return m_CosmeticDC.Orders.Single(theProect => theProect.OrderId == aProductId);
        }

        public Order GetOrderByIds1(string anOrderId)
        {
            return m_CosmeticDC.Orders.FirstOrDefault(theOrder => theOrder.OrderNum == anOrderId);
        }


        public OrderDetail GetOrderByIdes(Guid anOrderId)
        {
            return m_CosmeticDC.OrderDetails.Single(theProect => theProect.OrderId == anOrderId);
        }

        public Order GetOrderByorder(string anOrderId)
        {
            return m_CosmeticDC.Orders.Single(theProect => theProect.OrderNum == anOrderId);
        }


        //根据订单ID查询订单是否有订单详细信息
        public static DataSet GetAllProducts(Guid a)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "select [OrderDetailId] ,[OrderId],[ProductId],[Count]  from dbo.OrderDetail where OrderDetailId='" + a + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds;
            }
            finally
            {
                con.Close();
            }
        }

        //根据ID删除订单详细信息
        public static void DeleteSaleProduct(Guid ProductId)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "delete from dbo.OrderDetail where OrderDetailId = '" + ProductId + "'";

                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 根据orderID删除订单详细信息
        /// </summary>
        /// <param name="orderID"></param>
        public static void DeleteOrderDetail_ByOrderID(Guid orderID)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "delete from dbo.OrderDetail where OrderId = '" + orderID + "'";

                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }
        //根据ID删除订单信息

        public static void DeleteSaleProducts(Guid ProductId)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = "delete from [Order] where OrderId = '" + ProductId + "'";

                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        public IEnumerable<Order> GetOrdersByUser(Guid aUserId)
        {
            return m_CosmeticDC.Orders.Where(theOrder => theOrder.UserId == aUserId);
        }

        public Order GetOrderByUsers(Guid aUserId)
        {
            return m_CosmeticDC.Orders.FirstOrDefault(theOrder => theOrder.UserId == aUserId);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="anOrderDetail"></param>
        public void InsertOrderDetail(OrderDetail anOrderDetail)
        {
            m_CosmeticDC.OrderDetails.InsertOnSubmit(anOrderDetail);
            m_CosmeticDC.SubmitChanges();

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="anOrderDetail"></param>
        public void DeleteOrderDetail(OrderDetail anOrderDetail)
        {
            m_CosmeticDC.OrderDetails.DeleteOnSubmit(anOrderDetail);
            m_CosmeticDC.SubmitChanges();
        }

        /// <summary>
        /// 用于站内统计总共销售了多少件商品。
        /// </summary>
        /// <returns></returns>
        public static long CountingProduct()
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            string baseNumber = ConfigurationManager.AppSettings["baseNumber"].ToString();
            SqlConnection con = new SqlConnection(conStr);
            con.Open();
            try
            {
                string cmdStr = "SELECT  SUM(Count) AS Num FROM  OrderDetail WHERE  (OrderId IN   (SELECT  OrderId  FROM  [Order]))";
                SqlCommand com = new SqlCommand(cmdStr, con);
                object a = com.ExecuteScalar();
                string b = a.ToString();
                if (!string.IsNullOrEmpty(b))
                {
                    return Convert.ToInt64(a) + Convert.ToInt64(baseNumber);
                }
                else
                {
                    return Convert.ToInt64(baseNumber);
                }
            }
            finally
            {
                con.Close();
            }
        }



        //public static DataSet price(Guid userid)
        //{
        //    string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
        //    string baseNumber = ConfigurationManager.AppSettings["baseNumber"].ToString();
        //    SqlConnection con = new SqlConnection(conStr);
        //    con.Open();
        //    try
        //    {
        //        string cmdStr = "select sum(Price) as num,Year(CompleteTime) as years,month(CompleteTime) as mouth from [Order]where UserId ='" + userid + "' group by Year(CompleteTime) ,month(CompleteTime)";
        //        SqlCommand com = new SqlCommand(cmdStr, con);
        //        DataSet ds = new DataSet();
        //        SqlDataAdapter adap = new SqlDataAdapter(com);
        //        adap.Fill(ds);
        //        return ds;
        //    }
        //    finally
        //    {
        //        con.Close();
        //    }
        //}




        /// <summary>
        /// 用户取消订单操作。
        /// </summary>
        /// <param name="OrderNum"></param>
        public static void CancelOrder(string OrderNum)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(conStr);
            con.Open();
            try
            {
                string cmdStr = "update dbo.[Order] set State='取消' where OrderNum='" + OrderNum + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        ///  申请退款操作.
        /// 状态：1:未付款、2:已付款、3:已发货、4:申请退款、5:已退款、6:订单完成
        /// </summary>
        /// <param name="OrderID"></param>
        /// <param name="stateIndex"></param>
        public static void ModifyOrderState(string OrderID, int stateIndex)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(conStr);
            con.Open();
            try
            {
                string mstate = "未付款";
                switch (stateIndex)
                {
                    case 1: mstate = "未付款"; break;
                    case 2: mstate = "已付款"; break;
                    case 3: mstate = "已发货"; break;
                    case 4: mstate = "申请退款"; break;
                    case 5: mstate = "已退款"; break;
                    case 6: mstate = "订单完成"; break;
                }
                string cmdStr = "update dbo.[Order] set State='" + mstate + "' where OrderId='" + OrderID + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        ///  查找单个销售的商品
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="dateStart"></param>
        /// <param name="dateEnd"></param>
        /// <returns></returns>
        public static List<EntityBuyRecord> SelectIsNullPackageProduct(string userId, string dateStart, string dateEnd)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(conStr);
            con.Open();
            try
            {
                //四列：ProductName，PurchaseDate，PurchaseAmount，ProductCode
                string cmdStr = "SELECT [t2].[Name] AS [ProductName], [t0].[CreateTime] AS [PurchaseDate], [t0].[Price] AS [PurchaseAmount], [t1].[ProductCode] FROM [dbo].[Order] AS [t0] INNER JOIN [dbo].[OrderDetail] AS [t1] ON [t0].[OrderId] = [t1].[OrderId] and [t1].[PackageId] is null INNER JOIN [dbo].[Product] AS [t2] ON [t2].[ProductId] = [t1].[ProductId]  WHERE ([t0].[State] = '完成') AND ([t0].[UserId] = '" + userId + "') AND ([t0].[CreateTime] < '" + dateEnd + "') AND ([t0].[CreateTime] > '" + dateStart + "')";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);

                List<EntityBuyRecord> listBuyRecord = new List<EntityBuyRecord>();
                foreach (DataTable table in ds.Tables)
                {
                    foreach (DataRow theRow in table.Rows)
                    {
                        EntityBuyRecord entityBuyRecord = new EntityBuyRecord();
                        entityBuyRecord.ProductName = theRow["ProductName"].ToString();
                        entityBuyRecord.BuyDate = Convert.ToDateTime(theRow["PurchaseDate"]);
                        entityBuyRecord.ProductCode = theRow["ProductCode"].ToString();
                        entityBuyRecord.PurchaseAmount = Convert.ToDecimal(theRow["PurchaseAmount"]);
                        listBuyRecord.Add(entityBuyRecord);
                    }
                }
                return listBuyRecord;
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 查找捆绑销售的商品
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="dateStart"></param>
        /// <param name="dateEnd"></param>
        /// <returns></returns>
        public static List<EntityBuyRecord> SelectNotNullPackageProduct(string userId, string dateStart, string dateEnd)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(conStr);
            con.Open();
            try
            {
                //四列：ProductId1，ProductId2，ProductId3，PurchaseDagte，PurchaseAmount
                string cmdStr = "SELECT [t3].[ProductId1],[t3].[ProductId2],[t3].[ProductId3],  [t0].[CreateTime] AS [PurchaseDate], [t0].[Price] AS [PurchaseAmount] FROM [dbo].[Order] AS [t0] INNER JOIN [dbo].[OrderDetail] AS [t1] ON [t0].[OrderId] = [t1].[OrderId] and [t1].[PackageId] is not null INNER JOIN [dbo].[Product] AS [t2] ON [t2].[ProductId] = [t1].[ProductId] inner join [dbo].[PackageSales] AS [t3] on [t3].[Id] = [t1].[PackageId] WHERE ([t0].[State] = '完成') AND ([t0].[UserId] = '" + userId + "') AND ([t0].[CreateTime] < '" + dateEnd + "') AND ([t0].[CreateTime] > '" + dateStart + "')";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);

                List<EntityBuyRecord> listBuyRecord = new List<EntityBuyRecord>();
                foreach (DataTable table in ds.Tables)
                {
                    foreach (DataRow theRow in table.Rows)
                    {
                        //第一个商品
                        DataSet dsRow = SelectProductInfor(theRow["ProductId1"].ToString());
                        EntityBuyRecord entityBuyRecord = new EntityBuyRecord();
                        entityBuyRecord.ProductName = dsRow.Tables[0].Rows[0]["Name"].ToString();
                        entityBuyRecord.ProductCode = dsRow.Tables[0].Rows[0]["ProductCode"].ToString();
                        entityBuyRecord.PurchaseAmount = Convert.ToDecimal(dsRow.Tables[0].Rows[0]["网络零售价"].ToString());
                        entityBuyRecord.BuyDate = Convert.ToDateTime(theRow["PurchaseDate"]);
                        listBuyRecord.Add(entityBuyRecord);
                        // 第二个商品
                        DataSet dsRow2 = SelectProductInfor(theRow["ProductId2"].ToString());
                        EntityBuyRecord entityBuyRecord2 = new EntityBuyRecord();
                        entityBuyRecord2.ProductName = dsRow2.Tables[0].Rows[0]["Name"].ToString();
                        entityBuyRecord2.ProductCode = dsRow2.Tables[0].Rows[0]["ProductCode"].ToString();
                        entityBuyRecord2.PurchaseAmount = Convert.ToDecimal(dsRow2.Tables[0].Rows[0]["网络零售价"].ToString());
                        entityBuyRecord2.BuyDate = Convert.ToDateTime(theRow["PurchaseDate"]);
                        listBuyRecord.Add(entityBuyRecord2);
                        //第三个商品
                        DataSet dsRow3 = SelectProductInfor(theRow["ProductId3"].ToString());
                        EntityBuyRecord entityBuyRecord3 = new EntityBuyRecord();
                        entityBuyRecord3.ProductName = dsRow3.Tables[0].Rows[0]["Name"].ToString();
                        entityBuyRecord3.ProductCode = dsRow3.Tables[0].Rows[0]["ProductCode"].ToString();
                        entityBuyRecord3.PurchaseAmount = Convert.ToDecimal(dsRow3.Tables[0].Rows[0]["网络零售价"].ToString());
                        entityBuyRecord3.BuyDate = Convert.ToDateTime(theRow["PurchaseDate"]);
                        listBuyRecord.Add(entityBuyRecord3);
                    }
                }
                return listBuyRecord;
            }
            finally
            {
                con.Close();
            }
        }

        /// <summary>
        /// 根据productID来查找商品信息。
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public static DataSet SelectProductInfor(string productId)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;

            SqlConnection con = new SqlConnection(conStr);
            con.Open();
            try
            {
                string cmdStr = "select [Name],[网络零售价],[ProductCode] from [ProductInfo] where [ProductId] = '" + productId + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                DataSet ds = new DataSet();
                SqlDataAdapter adap = new SqlDataAdapter(com);
                adap.Fill(ds);
                return ds;
            }
            finally
            {
                con.Close();
            }
        }

        public IEnumerable GetAllorders1()
        {
            var result = from theFocus in m_CosmeticDC.Orders
                         join theProduct in m_CosmeticDC.Users
                         on theFocus.UserId equals theProduct.UserId
                         join thef in m_CosmeticDC.OrderDetails
                         on theFocus.OrderId equals thef.OrderId
                         join thefs in m_CosmeticDC.Products on
                         thef.ProductId equals thefs.ProductId
                         select new
                         {
                             OrderId = theFocus.OrderId,
                             //UserName = theProduct.UserName,
                             OrderNum = theFocus.OrderNum,
                             CreateTime = theFocus.CreateTime,
                             DeliveryAddress = theFocus.DeliveryAddress,
                             DeliveryCellPhone = theFocus.DeliveryCellPhone,
                             State = theFocus.State,
                             DeliveryTel = theFocus.DeliveryTel,
                             Valid = theFocus.Valid,
                             Intergral = theFocus.Intergral,
                             DeliveryPrice = theFocus.DeliveryPrice,
                             Price = theFocus.Price,
                             DeliveryTime = theFocus.DeliveryTime,
                             DeliveryType = theFocus.DeliveryType,
                             count = thef.Count,
                             productcode = thef.ProductCode,
                             Name = thefs.Name,
                         };
            return result;
        }



        public IEnumerable GetAllorders11(string order)
        {
            var result = from theFocus in m_CosmeticDC.Orders
                         join theProduct in m_CosmeticDC.Users
                         on theFocus.UserId equals theProduct.UserId
                         join thef in m_CosmeticDC.OrderDetails
                         on theFocus.OrderId equals thef.OrderId
                         join thefs in m_CosmeticDC.Products on
                         thef.ProductId equals thefs.ProductId
                         where theFocus.OrderNum == order
                         select new
                         {
                             OrderId = theFocus.OrderId,
                             //UserName = theProduct.UserName,
                             OrderNum = theFocus.OrderNum,
                             CreateTime = theFocus.CreateTime,
                             DeliveryAddress = theFocus.DeliveryAddress,
                             DeliveryCellPhone = theFocus.DeliveryCellPhone,
                             State = theFocus.State,
                             DeliveryTel = theFocus.DeliveryTel,
                             Valid = theFocus.Valid,
                             Intergral = theFocus.Intergral,
                             DeliveryPrice = theFocus.DeliveryPrice,
                             Price = theFocus.Price,
                             DeliveryTime = theFocus.DeliveryTime,
                             DeliveryType = theFocus.DeliveryType,
                             count = thef.Count,
                             productcode = thef.ProductCode,
                             Name = thefs.Name,
                         };
            return result;
        }

        public IEnumerable GetAllorders11a(Guid ordeid)
        {
            var result = from theFocus in m_CosmeticDC.Orders
                         join theProduct in m_CosmeticDC.Users
                         on theFocus.UserId equals theProduct.UserId
                         join thef in m_CosmeticDC.OrderDetails
                         on theFocus.OrderId equals thef.OrderId
                         join thefs in m_CosmeticDC.Products on
                         thef.ProductId equals thefs.ProductId
                         where theFocus.OrderId == ordeid
                         select new
                         {
                             OrderId = theFocus.OrderId,
                             //UserName = theProduct.UserName,
                             OrderNum = theFocus.OrderNum,
                             State = theFocus.State,
                             DeliveryAddress = theFocus.DeliveryAddress,
                             DeliveryCellPhone = theFocus.DeliveryCellPhone,
                             DeliveryTime = theFocus.DeliveryTime,
                             DeliveryType = theFocus.DeliveryType,
                             PayType = theFocus.PayType,
                             state = theFocus.State,
                             DeliveryTel = theFocus.DeliveryTel,
                             DeliveryPrice = theFocus.DeliveryPrice,
                             Price = theFocus.Price,
                             deliveryType = theFocus.DeliveryType,
                             count = thef.Count,
                             productcode = thef.ProductCode,
                             Name = thefs.Name,
                             DeliveryUserName = theFocus.DeliveryUserName,
                             CreateTime = theFocus.CreateTime,
                         };
            return result;
        }


        public List<Order> GetAllorders()
        {
            var result = (from theProduct in m_CosmeticDC.Orders
                          orderby theProduct.CreateTime descending
                          select theProduct).ToList();
            return result;
        }

        /// <summary>
        /// 根据订单号，会员登陆名，会员手机号查询订单。
        /// </summary>
        /// <param name="orderNum"></param>
        /// <param name="userName"></param>
        /// <param name="tel"></param>
        /// <returns></returns>
        public DataSet GetAllorders_Search(string orderNum, string userName, string tel,bool isApplyRefund)
        {
            DataSet ds = new DataSet();
            using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString))
            {
                con.Open();
                StringBuilder strBuild = new StringBuilder("select o.* from [Order] as o inner join [User] as u on o.UserId = u.UserId where 0=0 ");
                if (!string.IsNullOrEmpty(orderNum))
                {
                    strBuild.Append("  and o.OrderNum ='" + orderNum + "'  ");
                }
                if (!string.IsNullOrEmpty(userName))
                {
                    strBuild.Append("  and  u.[UserName]='" + userName + "'  ");
                }
                if (!string.IsNullOrEmpty(tel))
                {
                    strBuild.Append("  and  u.[tel]='" + tel + "'  ");
                }
                if (isApplyRefund)
                {
                    strBuild.Append("  and  o.[State]='申请退款'  ");
                }
                strBuild.Append(" order by CreateTime DESC");
                SqlDataAdapter adap = new SqlDataAdapter(strBuild.ToString(), con);
                adap.Fill(ds);
                con.Close();
            }
            return ds;
        }

        //public IEnumerable GetAllorders()
        //{
        //    var result = from theFocus in m_CosmeticDC.Orders
        //                 join theProduct in m_CosmeticDC.Users
        //                 on theFocus.UserId equals theProduct.UserId
        //                 orderby theFocus.CreateTime descending
        //                 select new
        //                 {
        //                     OrderId = theFocus.OrderId,
        //                     //UserName = theProduct.UserName,
        //                     OrderNum = theFocus.OrderNum,
        //                     CreateTime = theFocus.CreateTime,
        //                     DeliveryAddress = theFocus.DeliveryAddress,
        //                     DeliveryCellPhone = theFocus.DeliveryCellPhone,
        //                     State = theFocus.State,
        //                     DeliveryTel = theFocus.DeliveryTel,
        //                     Valid = theFocus.Valid,
        //                     Intergral = theFocus.Intergral,
        //                     DeliveryPrice = theFocus.DeliveryPrice,
        //                     Price = theFocus.Price,
        //                     DeliveryTime = theFocus.DeliveryTime,
        //                     DeliveryType = theFocus.PayType,
        //                     DeliveryUserName=theFocus.DeliveryUserName, 

        //                 };
        //    return result;
        //}

        public IEnumerable GetAllorderdetils(Guid orderid)
        {
            var result = from theFocus in m_CosmeticDC.OrderDetails
                         join theProduct in m_CosmeticDC.Products
                         on theFocus.ProductId equals theProduct.ProductId
                         where theFocus.OrderId == orderid
                         select new
                         {
                             ProductCode = theFocus.ProductCode,
                             Name = theProduct.Name,
                             Count = theFocus.Count,
                             OrderDetailId = theFocus.OrderDetailId,
                         };
            return result;
        }

        public static void UpdateInformation(decimal a, string rt, decimal bb1, bool ax, Guid bb)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = string.Empty;

                cmdStr = "UPDATE [Order]  SET [DeliveryType] ='" + a + "'  ,  [State]='" + rt + "',[Price] = '" + bb1 + "',[Valid]='" + ax + "' WHERE OrderId=" + bb + "";
                SqlCommand com = new SqlCommand(cmdStr, con);
                com.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }

        public static DataTable GetThePicturePath(string PictureSeat)
        {
            string conStr = ConfigurationManager.ConnectionStrings["CosmeticConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(conStr);
            try
            {
                con.Open();
                string cmdStr = string.Empty;
                cmdStr = "select * from [Order] where OrderId='" + PictureSeat + "'";
                SqlCommand com = new SqlCommand(cmdStr, con);
                SqlDataAdapter adap = new SqlDataAdapter(com);
                DataSet ds = new DataSet();
                adap.Fill(ds);
                return ds.Tables[0];
            }
            finally
            {
                con.Close();
            }
        }


        /// <summary>
        /// 判断是否存在此手机号的用户
        /// </summary>
        /// <param name="tel">The product want delete</param>

        public Order CheckExistes(string tel)
        {
            List<Order> theProductList = (from theProduct in m_CosmeticDC.Orders
                                          where theProduct.DeliveryCellPhone == tel
                                          select theProduct).ToList();
            if (theProductList.Count == 1)
            {
                return theProductList[0];
            }
            return null;
        }

        /// <summary>
        /// 根据email获取用户的详细信息
        /// </summary>
        /// <param name="tel">The product want delete</param>
        public Order CheckExistemail(Guid userid)
        {
            List<Order> theProductList = (from theProduct in m_CosmeticDC.Orders
                                          where theProduct.UserId == userid
                                          select theProduct).ToList();
            if (theProductList.Count >= 1)
            {
                return theProductList[0];
            }
            return null;
        }

    }
}
